package com.wq.common.utils

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import kotlin.properties.Delegates

/**
 * Created by WQ on 2017/6/27.
 */

class ViewEx(){
    var view: View by Delegates.notNull<View>()
    constructor(rootView: View, init: ViewEx.() -> Unit) :this() {
        view=rootView
        init()
    }
    fun <T: View> getView(id:Int):T{
        return view.findViewById(id) as T
    }

    fun textview(id:Int,init:TextView.()->Unit){
        getView<TextView>(id).apply(init)
    }
    fun image(id:Int,init:ImageView.()->Unit){
        getView<ImageView>(id).apply(init)
    }

}
